package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 苏成博
 * @date 2023-02-12 18:49
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据dishID,setnealId,dishFlavor三条信息使用动态sql查询
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> findShoppingCart(ShoppingCart shoppingCart);
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findShoppingCartByUserId(Long userId);

    /**
     * 更新购物车数据的数量
     *
     * @param shoppingCart
     */
    @Update("update Shopping_cart set number=#{number} where id =#{id}")
    void updateShoppingCart(ShoppingCart shoppingCart);

    void saveShoppinCart(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> listShoppingCart(Long userId);

    void deleteOne(ShoppingCart shoppingCart);

    /**
     * 根据用户id删除所有购物车数据
     *
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteAll(Long userId);
}
